﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.OleDb;

namespace Zatvor
{
    public partial class Interfejs : System.Web.UI.Page
    {
        bool dupli = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            activePlayer.ServiceNimic actPly = new activePlayer.ServiceNimic();
            int aktivenIgrac=actPly.getActivePlayerIndex();
            TextBoxId.Text = (aktivenIgrac).ToString();

            servisZatvor.zatvor z = new servisZatvor.zatvor();

            int br = z.vratiKazna(TextBoxId.Text.ToString());
           

            if (br == 3)
            {
                Button2.Visible = false;
                Button1.Visible = false;
                Button4.Visible = true;
            }
            if (br == 0)
            {
                Button2.Visible = false;
                Button1.Visible = false;
                Button4.Visible = false;
                ButtonOslobodi.Visible = true;
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {            
            activePlayer.ServiceNimic actPly = new activePlayer.ServiceNimic();
            int aktivenIgrac=actPly.getActivePlayerIndex();

            banka.Banka b = new banka.Banka();            
            b.withdrawMoney(aktivenIgrac, 50);
            
            servisZatvor.zatvor z = new servisZatvor.zatvor();

            z.platiBanka(TextBoxId.Text.ToString());

            Button2.Visible = false;
            Button1.Visible = false;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            

            kocka.Service1 br1 = new kocka.Service1();

            string brojce1 = br1.RndNumber();

            string[] rezultat = brojce1.Split('\n');
            //broj1.Text = "Добиен број: " + rezultat[0].ToString() + " ";

            //za brisenje \|/

            

            if (String.Compare(rezultat[0].ToString(),"1")==0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl="~/kocka/1.png";
            }
            if (String.Compare(rezultat[0].ToString(), "2") == 0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl = "~/kocka/2.png";
            }
            if (String.Compare(rezultat[0].ToString(), "3") == 0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl = "~/kocka/3.png";
            }
            if (String.Compare(rezultat[0].ToString(), "4") == 0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl = "~/kocka/4.png";
            }
            if (String.Compare(rezultat[0].ToString(), "5") == 0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl = "~/kocka/5.png";
            }
            if (String.Compare(rezultat[0].ToString(), "6") == 0)
            {
                ImageButton1.Visible = true;
                ImageButton1.ImageUrl = "~/kocka/6.png";
            }

            kocka.Service1 br2 = new kocka.Service1();

            string brojce2 = br2.RndNumber();

            string[] rezultat1 = brojce2.Split('\n');
            
            //broj2.Text = "Добиен број: " + rezultat1[0].ToString() + " ";

            //za brisenje \|/

            

            if (String.Compare(rezultat1[0].ToString(), "1") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/1.png";
            }
            if (String.Compare(rezultat1[0].ToString(), "2") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/2.png";
            }
            if (String.Compare(rezultat1[0].ToString(), "3") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/3.png";
            }
            if (String.Compare(rezultat1[0].ToString(), "4") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/4.png";
            }
            if (String.Compare(rezultat1[0].ToString(), "5") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/5.png";
            }
            if (String.Compare(rezultat1[0].ToString(), "6") == 0)
            {
                ImageButton2.Visible = true;
                ImageButton2.ImageUrl = "~/kocka/6.png";
            }

            if (String.Compare(rezultat[0].ToString(), rezultat1[0].ToString()) == 0)
            {
                dupli = true;
                //duplite.Text = "ДУПЛИ!";
            }
            else
            {
                dupli = false;
                //duplite.Text = "Добар обид!";
            }


            if (dupli == true)
            {              
                  
                servisZatvor.zatvor z = new servisZatvor.zatvor();

                z.platiBanka(TextBoxId.Text.ToString());

                Button2.Visible = false;
                Button1.Visible = false;

            }
            else
            {               

                servisZatvor.zatvor z = new servisZatvor.zatvor();
                z.nePadnaaDupli(TextBoxId.Text.ToString());

                Button2.Visible = false;
                Button1.Visible = false;
                ButtonOslobodi.Visible = false;
            }                 

        }

        protected void Button4_Click(object sender, EventArgs e)
        {            
            servisZatvor.zatvor z = new servisZatvor.zatvor();
            z.voZatvor(TextBoxId.Text.ToString());

            Button2.Visible = false;
            Button1.Visible = false;
            Button4.Visible = false;
        }

        protected void ButtonOslobodi_Click(object sender, EventArgs e)
        {
            servisZatvor.zatvor z = new servisZatvor.zatvor();
            z.oslobodiOdZatvor(TextBoxId.Text.ToString());

            ButtonOslobodi.Visible = false;
        }

    }
}


